import { createSlice } from "@reduxjs/toolkit";

const counterStore = createSlice({
    name: 'counter',
    initialState: { count: 0 },
    reducers: {
        increment(state){
            state.count++
        },
        decrement(state){
            state.count--
        },
        add2Num(state, action){
            state.count = action.payload
        }
    }
})

// 结构出来 actionCreater
const { increment, decrement, add2Num } = counterStore.actions
const reducer = counterStore.reducer

// 按需导出 actionCreater
export { increment, decrement, add2Num }
// 使用默认导出的方式导出 reducer
export default reducer